package com.csun.cmny.provider.service.impl;

import com.alibaba.fastjson.JSON;
import com.csun.cmny.base.constant.AliyunMqTopicConstants;
import com.csun.cmny.base.constant.AliyunSmsConstants;
import com.csun.cmny.base.enums.ErrorCodeEnum;
import com.csun.cmny.provider.model.domain.MqMessageData;
import com.csun.cmny.provider.model.dto.SendWebSocketRequest;
import com.csun.cmny.util.RedisKeyUtil;
import com.google.common.collect.Maps;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

import java.util.Map;

/**
 * @Auther: chisj chisj@foxmal.com
 * @Date: 2019-10-11 14:07
 * @Description:
 */
@Slf4j
@Component
public class WebSocketProducer {

    public MqMessageData sendWebSocketMq(SendWebSocketRequest webSocketRequest) {

        log.info("websocket发送消息. webSocketRequest={}", webSocketRequest);
        String msgBody;
        try {
            msgBody = JSON.toJSONString(webSocketRequest);
        } catch (Exception e) {
            log.error("发送短信验证码 smsMessage转换为json字符串失败", e);
            throw new RuntimeException("发送短信验证码 smsMessage转换为json字符串失败");
        }
        String topic = AliyunMqTopicConstants.MqTopicEnum.SEND_WEBSOEKCT_TOPIC.getTopic();
        String tag = webSocketRequest.getMsgType();
        String key = RedisKeyUtil.createMqKey(topic, tag, webSocketRequest.getRefNo(), msgBody);

        return new MqMessageData(msgBody, topic, tag, key);
    }

}
